package com.shxzz.easy12306.services.ticket.config;

import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
import cn.hippo4j.core.executor.DynamicThreadPool;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * 线程池配置
 * @author shxzz
 * @create 2024-03-07-17:06
 */
@Configuration
public class ThreadPoolConfiguration {

    @Bean
    @DynamicThreadPool
    public ThreadPoolExecutor selectSeatThreadPoolExecutor() {
        return ThreadPoolBuilder.builder()
                .threadPoolId("select-seat-thread-pool")
                .threadFactory("select-seat")
                .corePoolSize(24)
                .maximumPoolSize(36)
                .workQueue(BlockingQueueTypeEnum.SYNCHRONOUS_QUEUE)
                .allowCoreThreadTimeOut(true)
                .keepAliveTime(60, TimeUnit.MINUTES)
                .rejected(new ThreadPoolExecutor.CallerRunsPolicy())
                .dynamicPool()
                .build();
    }

}
